<?php
class Model_Country extends Model_Base {
   protected $_pk = 'id';
   protected $_fields = array('id', 'continent_id', 'cc', 'name');
   protected $_table = 'countrycodes';
   protected $_name = 'countrycodes';
   
   
   function getCountryList($name='countrylist', $attribs=array()) {
      
      $db = Zend_Registry::get('db');
      $sql = sprintf("
         SELECT 
            cc.id as 'countryid', cc.cc, cc.continent_id, cc.name as 'country', c.name as 'continent'
         FROM 
            countrycodes cc
            LEFT JOIN continents c on (cc.continent_id = c.id)
         ORDER BY 
            cc.continent_id, cc.id
      ", $args);
      $rows = $db->fetchAll($sql);
      if(!$rows) {
         return null;
      }
      $arr = array();
      foreach($rows as $row) {
         if($row['continent']) {
            $arr[$row['continent']][$row['cc']] = $row['country'];
         }
      }
      
      return $arr;
      
   }
}


